package com.syscom.qcRule.util;

import java.util.HashMap;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.syscom.frmcommon.SystemException;

/**
 * @author Jean
 */
public class GetQCRuleUtil {
    @SuppressWarnings("unused")
	private transient static final String mark = "10BCC85DDC54DDF27A18E78A2AA7EB50A27C9789E7CDBE9FD4DD9C9DC56D7247A585625B8AE77885";
	private static Logger mLogger = Logger.getLogger(GetQCRuleUtil.class.getName());
    private static HashMap<Integer,QCRuleCal> instanceMap = new HashMap<Integer,QCRuleCal>();
    
    private GetQCRuleUtil() {}
    
    public static QCRuleCal getInstance(int iRuleId){
        String classPath = GetQCRulePathUtil.getInstance().getRulePath(iRuleId);
        if (instanceMap.containsKey(iRuleId)) {
            return (QCRuleCal)instanceMap.get(iRuleId);
        }
        else{
            try {
                Class aClass = Class.forName(classPath, true, QCRuleCal.class.getClassLoader());
                QCRuleCal rule = (QCRuleCal)aClass.newInstance();
                instanceMap.put(iRuleId, rule);
                return rule;
            }
            catch (Exception e) {
            	if (mLogger.isEnabledFor(Level.ERROR)) {
    				mLogger.log(Level.ERROR, e.getMessage(), e);
            	}
                throw new SystemException(e, SystemException.SEVERE);
            }
        }
    }
}

